<template>
  <div>
    <el-dialog
        :title="modalTile"
        :visible.sync="dialogVisible"
        :close-on-click-modal="false"
        width="500px">
      <div>
        <el-form :model="formData" label-width="0">
          <quick-input @change="inputChange"/>
          <el-form-item label="">
            <el-input v-model="formData.error" type="textarea" :rows="3"
                      :placeholder="status === '1' ? '请填写标错原因':'请填写撤销标错原因'"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import {Component, Vue,Prop} from 'vue-property-decorator';
import {dataError} from "@/api/dataApproval";
import QuickInput from "@/views/quality/components/QuickInput.vue";

@Component({
  components: {QuickInput}
})
export default class ErrorModal extends Vue {
  modalTile = '';
  status = '';
  @Prop() workId:any;
  private ids: any = []
  private id: any = ''
  private categoryId: any = ''
  private categoryLevel: any = ''
  private formData: any = {
    status: '1',
    error: ''
  }
  dialogVisible = false;

  public showModal(modalTile, ids, status) {
    this.status = status
    this.modalTile = modalTile
    if(ids.length == 1){
      this.id = ids[0];
    }else{
      this.ids = ids
    }

    this.dialogVisible = true;
  }

  submit() {
    this.$msgbox.confirm(`是否确认${this.modalTile}`, {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(async () => {
      const formData = Object.assign({}, this.formData)
      formData.id = this.id
      formData.status = this.status
      
      formData.ids = this.ids
      formData.workId= this.workId
      await dataError(formData)
      this.$message.success('提交成功')
      this.dialogVisible = false;
      this.$emit('success')
    }).catch(() => {
      this.dialogVisible = false;
    })
  }

  categoryCheckHandler(item) {
    this.categoryId = item.id
    this.categoryLevel = item.level
  }

  inputChange(value) {
    this.formData.error = value
  }
}
</script>
<style lang="scss" scoped>
</style>
